from __future__ import absolute_import

from file_parser import *
from make_file_base import *

# ------------------------------------------------------------------------------------------------------#

def make_cpptoc_header_file(header, dir_path, dir_name, class_name):
  cls = header.get_class(class_name)
  if cls is None:
    raise Exception('Class does not exist: ' + class_name)

  content = get_copyright()
  content += '\n'

  content += \
"""
#ifndef $GUARD$
#define $GUARD$
#pragma once
"""
  content += '\n'

  result = make_include_file(cls, 'CppToC', header, dir_name, class_name)
  content += result['content']
  content += '\n'

  content += 'namespace OHOS::ArkWeb {\n\n'

  content += '// Wrap a C++ class with a C structure.\n'
  content += '// This class may be instantiated and accessed DLL-side only.\n'
  content += make_class_define(cls, 'CppToC', result['base_name'], class_name, '')
  content += '\n'

  content += '} // OHOS::ArkWeb\n\n'
  
  content += \
"""
#endif // $GUARD$
"""

  # add the guard string
  def_name = make_def_file(cls, class_name)
  guard = def_name.upper() + '_CPPTOC_H_'
  content = content.replace('$GUARD$', guard)
  
  absolute_path = os.path.join(dir_path, get_capi_name(class_name, False) + '_cpptoc.h')
  return (content, absolute_path)

